package com.springapi.service.impl;

import com.springapi.entity.Routes;
import com.springapi.dao.RoutesDao;
import com.springapi.service.RoutesService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Routes)表服务实现类
 *
 * @author makejava
 * @since 2024-11-28 08:28:03
 */
@Service("routesService")
public class RoutesServiceImpl implements RoutesService {
    @Resource
    private RoutesDao routesDao;


    @Override
    public List<Routes> findByAppName(String appName) {
        return routesDao.findByAppName(appName);
    }

    @Override
    public List<Routes> findByAppuserid(Integer id) {
        return routesDao.findByAppuserid(id);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Routes queryById(Integer id) {
        return this.routesDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param routes 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Routes> queryByPage(Routes routes, PageRequest pageRequest) {
        long total = this.routesDao.count(routes);
        return new PageImpl<>(this.routesDao.queryAllByLimit(routes, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param routes 实例对象
     * @return 实例对象
     */
    @Override
    public Routes insert(Routes routes) {
        this.routesDao.insert(routes);
        return routes;
    }

    /**
     * 修改数据
     *
     * @param routes 实例对象
     * @return 实例对象
     */
    @Override
    public Routes update(Routes routes) {
        this.routesDao.update(routes);
        return this.queryById(routes.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.routesDao.deleteById(id) > 0;
    }
}
